package com;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;

public class E {
    public static ThreadPoolExecutor threadPool = new ThreadPoolExecutor(40, 200, 500, TimeUnit.SECONDS,
            new ArrayBlockingQueue<Runnable>(100*180), new ThreadPoolExecutor.DiscardOldestPolicy());

    public static void main(String[] args) throws InterruptedException {
        long starttime =System.currentTimeMillis();

        List<Map<String, Integer>> maps = new ArrayList<Map<String, Integer>>();
        for (int i = 0; i <180 ; i++) {
            Map<String, Integer> map = new HashMap<>();
            map.put("name", i);
            map.put("age", i*10+1);
            maps.add(map);
        }
        CountDownLatch c1=new CountDownLatch(100*180);
        for (int k = 0; k<100 ; k++) {
            for (final  Map<String, Integer> map2 : maps) {
                if(map2.get("name")*10+1!= map2.get("age")){
                    System.out.println(map2.get("name")+"====="+map2.get("age"));
                }

            //System.out.println("==============");
            for (final  Map<String, Integer> map : maps) {
                Runnable runnable = new Runnable(){
                    Map<String, Integer> map1 = new HashMap<>();
                    @Override
                    public void run() {
                        //            System.out.println(Thread.currentThread().getId());
                        if(map.get("name")*10+1!= map.get("age")){
                            System.out.println(map.get("name")+"====="+map.get("age"));
                        }
//            System.out.println(map.get("name")+"====="+map.get("age"));

                        map1.put("name",map.get("name"));
                        map1.put("age",map.get("age"));

                        if(map1.get("name")*10+1!= map1.get("age")){
                            System.out.println(map.get("name")+"====="+map.get("age"));
                            System.out.println(map1.get("name")+"====="+map1.get("age"));
                            System.out.println("*****************");
                        }
                        if(map1.get("name")!= map.get("name")){
                            System.out.println(map.get("name")+"====="+map.get("age"));
                            System.out.println(map1.get("name")+"====="+map1.get("age"));
                            System.out.println("%%%%%%%%%%%%%%%%%%%%%%");
                        }

                        c1.countDown();
                    }
                };
                threadPool.execute(runnable);
            }}
        }
        c1.await();
        long endtime =System.currentTimeMillis();
        System.out.println(endtime-starttime);
        threadPool.shutdownNow();
    }
}
